package com.yun.algorithmproblem.leetcode;

public class Leetcode2145 {

	public static void main(String[] args) {
		Leetcode2145 obj=new Leetcode2145();
		obj.numberOfArrays(new int[]{1,-3,4},1,6);
	}

	public int numberOfArrays(int[] differences, int lower, int upper) {
		int max = 0, min = 0;
		int curr = 0;
		for (int difference : differences) {
			curr += difference;
			if (difference >= 0) {
				max=Math.max(max,curr);
			}else {
				min=Math.min(min,curr);
			}
		}
		int ans=(upper-lower)-(max-min)+1;
		return Math.max(ans, 0);
	}
}
